<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>自然资源添加页面</title>
  <link rel="stylesheet" href="../../../yl/index.css" />
  <!-- 布局样式 -->
  <link rel="stylesheet" href="../../../yl/style.css" />
  <link rel="stylesheet" href="../../../yl/mobile.css" />
  <link rel="stylesheet" href="../../../yl/easyui.css" />
  <link rel="stylesheet" href="../../../yl/icon.css" />
</head>

<body>
  <!-- <div id="app"> -->
  <div class="easyui-navpanel" id="app" v-cloak>
    <header>
      <div class="m-toolbar">
        <div class="m-title">{{action=='Add'?'添加自然资源信息':action=='Modify'?'修改自然资源信息':''}}</div>
      </div>
    </header>
    <div class="easyui-navpanel panel-body panel-body-nobottom panel-body-noborder" style="height: 3000px"
      id="MainTable" ref="MainTable"
      :data-options="JSON.stringify({ 'TableName': 'natural_resources_management', 'form': 'dataForm' ,'primary_key':'Natural_Resource_SerialNumber' })">
      <div class="yl-main">
        <div class="table_titel">
          <div class="titel">自然资源信息</div>
        </div>
        <el-descriptions :column="1" size="large" border>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">自然资源名称</div>
            </template>
            <el-input v-model="dataForm.Natural_Resource_Name" class="borderless-input"
              placeholder="请输入自然资源名称" />
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">自然资源类别</div>
            </template>
            <el-select clearable v-model.trim="dataForm.Resource_Category_SerialNumber" placeholder="请选择自然资源" filterable
              style="width: 100%">
              <el-option v-for="(item,index) in category" :key="index" :label="item.Resource_Category"
                :value="item.Resource_Category_SerialNumber"></el-option>
            </el-select>
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">村行政区</div>
            </template>
            <el-select @change="changeVillage" clearable v-model.trim="dataForm.Village_SerialNumber" placeholder="请选择村行政区" filterable
              style="width: 100%">
              <el-option v-for="(item,index) in village" :key="index" :label="item.Village"
                :value="item.VillageNumber"></el-option>
            </el-select>
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">村集体</div>
            </template>
            <el-select @change="changeAddress" :disabled="!dataForm.Village_SerialNumber" clearable v-model.trim="dataForm.Village_Collective_SerialNumber" placeholder="请选择村集体" filterable
              style="width: 100%">
              <el-option v-for="(item,index) in village_Collective" :key="index" :label="item.Org_Name"
                :value="item.Village_Collective_SerialNumber"></el-option>
            </el-select>
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">面积（亩）</div>
            </template>
            <el-input v-model="dataForm.Area" class="borderless-input" placeholder="请输入面积" />
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">地图</div>
            </template>
            <div class="container map-container">
              <!-- 天地图容器，移除绝对定位并添加到地图容器中 -->
              <div id="mapDiv" style="width: 100%; height: 400px; border: 1px solid #ccc"></div>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">坐标集</div>
            </template>
            <el-input disabled v-model="dataForm.Coords" class="borderless-input"
              placeholder="请输入坐标集" />
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">质量等级</div>
            </template>
            <el-input v-model="dataForm.Quality_Grade" class="borderless-input"
              placeholder="请输入质量等级" />
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">自然资源用途</div>
            </template>
            <!-- <el-select clearable v-model.trim="dataForm.Natural_Resource_Usage_SerialNumber" placeholder="请选择自然资源用途" filterable
              style="width: 100%">
              <el-option v-for="(item,index) in Natural_Resource_Usage" :key="index" :label="item.Natural_Resource_Usage_Name"
                :value="item.Natural_Resource_Usage_SerialNumber"></el-option>
            </el-select> -->
            <el-cascader @change="changeCity" class="borderless-input" v-model="cityValue" filterable
              :props="{value:'Natural_Resource_Usage_SerialNumber',label:'Natural_Resource_Usage_Name',children:'children'}" placeholder="请选择自然资源用途" :options="Natural_Resource_Usage"
              style="width: 100%"></el-cascader>
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">使用状态</div>
            </template>
            <el-select clearable v-model.trim="dataForm.Usage_status" placeholder="请选择使用状态" filterable style="width: 100%">
              <el-option v-for="(item,index) in Usage_status" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-descriptions-item>
        </el-descriptions>
        <div id="ChildTable">
          <div class="table_titel">
            <div class="titel">自然资源对应标签</div>
            <div class="operation">
              <el-button type="primary" size="small" @click="handleAdd('childDataForm')">新增</el-button>
              <el-button type="danger" size="small" @click="handleRemove('childDataForm')">删除</el-button>
            </div>
          </div>
          <el-descriptions
            :data-options="JSON.stringify({ 'TableName': 'natural_resources_mapping_tags', 'form': 'childDataForm', 'ParentTableName': 'natural_resources_management'})"
            :column="2" size="large" border v-for="(item,index) in childDataForm.filter(item => item.Row_Status != '1')"
            :key="index">
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">标签</div>
              </template>
              <el-select clearable v-model.trim="item.Natural_Resource_Tag_SerialNumber" placeholder="请选择流水类型" filterable
                style="width: 100%">
                <el-option v-for="(item,index) in Natural_Resource_Tag" :key="index" :label="item.Natural_Resource_Tag" :value="item.Natural_Resource_Tag_SerialNumber"></el-option>
              </el-select>
            </el-descriptions-item>
          </el-descriptions>
          <!-- <div class="table_titel">
            <div class="titel">自然资源承包合同</div>
            <div class="operation">
              <el-button type="primary" size="small" @click="handleAdd('childDataForm1')">新增</el-button>
              <el-button type="danger" size="small" @click="handleRemove('childDataForm1')">删除</el-button>
            </div>
          </div>
          <el-descriptions
            :data-options="JSON.stringify({ 'TableName': 'natural_resources_management', 'form': 'childDataForm1', 'ParentTableName': 'natural_resources_management'})"
            :column="2" size="large" border v-for="(item,index) in childDataForm1.filter(item => item.Row_Status != '1')"
            :key="index">
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">承包方名称</div>
              </template>
              <el-input v-model="item.Contractor_Name" class="borderless-input"
                placeholder="请输入承包方名称" />
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">承包方类型</div>
              </template>
              <el-input v-model="item.Contractor_Type" class="borderless-input"
                placeholder="请输入承包方类型" />
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">证件编号</div>
              </template>
              <el-input v-model="item.ID_Number" class="borderless-input"
                placeholder="请输入证件编号" />
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">联系电话</div>
              </template>
              <el-input v-model="item.Contact_Phone" class="borderless-input"
                placeholder="请输入联系电话" />
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">合同金额</div>
              </template>
              <el-input v-model="item.Contract_Amount" class="borderless-input"
                placeholder="请输入合同金额" />
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">付款周期</div>
              </template>
              <el-input v-model="item.Payment_Cycle" class="borderless-input"
                placeholder="请输入付款周期" />
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">签订日期</div>
              </template>
              <el-date-picker v-model="item.Sign_Date" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                class="borderless-input" type="date" placeholder="请选择签订日期" size="large"></el-date-picker>
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">生效日期</div>
              </template>
              <el-date-picker v-model="item.Start_Date" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                class="borderless-input" type="date" placeholder="请选择生效日期" size="large"></el-date-picker>
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">结束日期</div>
              </template>
              <el-date-picker v-model="item.End_Date" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                class="borderless-input" type="date" placeholder="请选择结束日期" size="large"></el-date-picker>
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">合同状态</div>
              </template>
              <el-input v-model="dataForm.Contract_Status" class="borderless-input"
                placeholder="请输入合同状态" />
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <div class="cell-item">合同路径</div>
              </template>
              <yl-upload drag v-model="item.Attachment_Path"></yl-upload>
            </el-descriptions-item>
          </el-descriptions> -->
        </div>
      </div>
      
    </div>
    <footer class="botton-ann">
      <el-button @click="goBack">返回</el-button>
      <el-button type="primary" plain @click="handleSubmit" :loading="loading">提交</el-button>
    </footer>
  </div>
</body>
<script src="../../../utils/utils.js"></script>
<script src="../../../config/config.js"></script>
<script src="../../../utils/mixins.js"></script>
<script src="../../../yl/vue.js"></script>
<script src="../../../yl/index.js"></script>
<script src="../../../yl/zh-cn.mjs"></script>
<script src="../../../yl/index.iife.min.js"></script>
<script src="../../../yl/jquery.min.js"></script>
<script src="../../../utils/jquery.cookie.js"></script>
<script src="../../../yl/jquery.easyui.min.js"></script>
<script src="../../../yl/jquery.easyui.mobile.js"></script>
<script src="../../../yl/moment.min.js"></script>
<script src="../../../api/request.js"></script>
<script src="./js/api.js"></script>
<script src="./js/getscript.js"></script>
<script src="./js/add.js"></script>
<script type="text/javascript">
  var map,
    zoom = 12;
  marker = null;
  function onLoad() {
    // 获取DOM元素和初始值
    const lcenterElement = document.getElementById("lcenter");
    let initialValue = lcenterElement.value;

    // 初始化地图
    map = new TMap("mapDiv");
    let marker; // 声明标注变量

    // 处理初始坐标
    if (initialValue) {
      try {
        const values = JSON.parse(initialValue);
        const lng = values[0];
        const lat = values[1];

        map.centerAndZoom(new TLngLat(lng, lat), zoom);
        marker = new TMarker(new TLngLat(lng, lat));
        map.addOverLay(marker);
      } catch (error) {
        console.error("初始坐标解析失败:", error);
        map.centerAndZoom(new TLngLat(122.545418, 52.978303), zoom); // 默认北京坐标
      }
    } else {
      map.centerAndZoom(new TLngLat(122.545418, 52.978303), zoom); // 默认北京坐标
    }
    // 添加输入事件监听（核心逻辑）
    lcenterElement.addEventListener("input", function () {
      const newValue = this.value;
      console.log("坐标值更新:", newValue);
      // 防止空值导致错误
      if (!newValue) return;
      try {
        const values = JSON.parse(newValue);
        const lng = values[0];
        const lat = values[1];

        // 更新地图和标注
        map.centerAndZoom(new TLngLat(lng, lat), zoom);

        // 优化标注更新：先移除再添加，避免多个标注
        if (marker) map.removeOverLay(marker);
        marker = new TMarker(new TLngLat(lng, lat));
        map.addOverLay(marker);
      } catch (error) {
        console.error("坐标解析失败:", error);
        // 可以添加错误提示或自动填充默认值
      }
    });
  }
  // 百度坐标系(BD-09)转WGS-84
  function bd09ToWGS84(bd_lon, bd_lat) {
    var gcj = bd09ToGcj02(bd_lon, bd_lat);
    return gcj02ToWGS84(gcj.lng, gcj.lat);
  }
  // 百度坐标系(BD-09)转火星坐标系(GCJ-02)
  function bd09ToGcj02(bd_lon, bd_lat) {
    var x = bd_lon - 0.0065,
      y = bd_lat - 0.006;
    var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * Math.PI);
    var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * Math.PI);
    var gcj_lon = z * Math.cos(theta);
    var gcj_lat = z * Math.sin(theta);
    return { lng: gcj_lon, lat: gcj_lat };
  }
  // BD-09(百度坐标系)转GCJ-02(腾讯、高德坐标系)
function bd09ToGCJ02(bdLng, bdLat) {
    const x = bdLng - 0.0065;
    const y = bdLat - 0.006;
    const z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * Math.PI * 3000.0 / 180.0);
    const theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * Math.PI * 3000.0 / 180.0);
    const ggLng = z * Math.cos(theta);
    const ggLat = z * Math.sin(theta);
    return { lng: ggLng, lat: ggLat };
}
  // 火星坐标系(GCJ-02)与WGS-84互转（简化版）
  function gcj02ToWGS84(gcj_lon, gcj_lat) {
    // 中国区域内GCJ-02到WGS-84的偏移参数（简化模型）
    var dLon = 0.0065;
    var dLat = 0.006;
    var radLat = (gcj_lat / 180) * Math.PI;
    var magic = Math.sin(radLat);
    magic = 1 - 0.0025 * Math.cos(2 * radLat);
    var sqrtMagic = Math.sqrt(magic);

    var wgs_lon =
      gcj_lon -
      (dLon * 180) / ((Math.PI * 6378137 * Math.cos(radLat)) / sqrtMagic);
    var wgs_lat = gcj_lat - (dLat * 180) / ((Math.PI * 6378137) / sqrtMagic);

    return { lng: wgs_lon, lat: wgs_lat };
  }
</script>
</html>